<?php
defined('_JEXEC') or die('Restricted access'); 
 
JHtml::_('formbehavior.chosen', 'select');
JHtml::_('jquery.framework');
JHtml::_('behavior.keepalive');
JHtml::_('behavior.framework');
JHTML::_('behavior.modal');
$user_group = $this->user->groups[16];

?>
 
<link href="<?php echo JURI::base(true)?>/components/com_wrd/assets/css/uploadify.css" type="text/css" rel="stylesheet" />
<link href="<?php echo JURI::base(true)?>/components/com_wrd/assets/css/jquery.autocomplete.css" type="text/css" rel="stylesheet" />
	


<script type="text/javascript" src="<?php echo JURI::base(true)?>/components/com_wrd/assets/js/swfobject.js"></script>
<script type="text/javascript" src="<?php echo JURI::base(true)?>/components/com_wrd/assets/js/jquery.uploadify.v2.1.4.min.js"></script>
<script type="text/javascript" src="<?php echo JURI::base(true)?>/components/com_wrd/assets/js/jquery.autocomplete.js"></script>

<script type="text/javascript">
	function submitform(pressbutton){
		var form = document.adminForm;
		if (pressbutton){
			form.task.value=pressbutton;
		}
		if (pressbutton=='apply' || pressbutton=='save' || pressbutton=='cancel' || pressbutton=='uPoint' || pressbutton == 'uSpend')
		{
			form.controller.value="profile";
			form.submit();
		}
	}
	
	function showOther(ex,id){
		if(jQuery("select#"+ex+" option:selected").val()=='other'){
			jQuery("."+id).css('display','') ;
		}else{
			jQuery("."+id).css('display','none') ;
		}
	}

	jQuery(document).ready(function() {
		jQuery('#image_upload').uploadify({
		    'uploader'  	: '<?php echo JURI::base(true)?>/components/com_wrd/assets/flash/uploadify.swf',
		    'script'    	: '<?php echo JURI::base(true)?>/components/com_wrd/classes/fileUploader.php',
		    'cancelImg' 	: '<?php echo JURI::base(true)?>/components/com_wrd/assets/images/cancel.png',
		    'folder'    	: '<?php echo str_ireplace('administrator', '', JURI::base(true)).'wrd' ?>',
		    'fileExt'		: '*.jpg;*.png',
	    	'fileDesc'		: 'Web Image Files (.JPG , .PNG)',
		    'auto'      	: true,
		    'scriptData'  	: {'typeupload':'profile','userid':<?php echo $this->user->id ; ?>},
		    'onComplete'  	: function(event, ID, fileObj, response, data) {
		    	obj = jQuery.parseJSON(response);
	        	jQuery('#imagefile').html('<div class="image_prview_pro"><img src="<?php echo JURI::base(true).'/../wrd/thumb/'?>'+obj.filename+'" width="100" height="100" /><a style="position:absolute;right:-7px;top:-10px;" onclick="remove_image('+obj.fileid+')" href="javascript:void(null)"><img src="<?php echo JURI::base(true).'/components/com_wrd/assets/images/remove.png'?>" /></a></div>');
	        	jQuery('#image_uploadUploader').hide();
			}
		});
	});
	

	function remove_image(id){
		jQuery.ajax({
			url: "index.php?option=com_wrd&task=removefile",
			type: "POST",
			data: 'id='+id,
			success: function (res) {
				jQuery('#image_'+id).remove();
				jQuery('#image_uploadUploader').show();
				jQuery('#imagefile').html('<div class="image_prview_pro"></div>');
				jQuery('#form_account_top').css('display','') ;
			}
		});
	}
	Joomla.submitbutton = function(pressbutton){
		if (pressbutton == 'cancel' || pressbutton=='newitem' ) {
			submitform( pressbutton );
			return;
		}
		if (pressbutton == 'save' || pressbutton == 'apply' || pressbutton == 'uPoint' || pressbutton == 'uSpend') {
			
			submitform( pressbutton );
		}
	}
	var sectioncountrys = new Array;
	<?php
		foreach ($this->lists['countryToCity'] as $k=>$item) {
			echo "sectioncountrys[".$k."] = new Array( '$item->country_id','".addslashes( $item->id )."','".addslashes( $item->name )."' );\n\t\t";
		}
	?>
	var sectioncitys = new Array;
	<?php
		foreach ($this->lists['cityToDistric'] as $k=>$item) {
			echo "sectioncitys[".$k."] = new Array( '$item->city_id','".addslashes( $item->id )."','".addslashes( $item->name )."' );\n\t\t";
		}
	?>

	function changeCity( listname, source, key, orig_key, orig_val ) {
		var list = eval( 'document.adminForm.' + listname );

		// empty the list
		for (i in list.options.length) {
			list.options[i] = null;
		}
		
		var i = 0;
		var j = 0;
		//if(i == 0){
			opt = new Option();
			opt.value = 0;
			opt.text = '- Select City -';
			opt.selected = true;
			
			list.options[i++] = opt;
		//}
		if(key == 249){
			opt = new Option();
			opt.value = 1;
			opt.text = "Ho Chi Minh";
			list.options[i++] = opt;
		}
		for (x in source) {
			if (source[x][0] == key) {
				if(source[x][1] != 1){
					opt = new Option();
					opt.value = source[x][1];

					opt.text = source[x][2];

					if ((orig_key == key && orig_val == opt.value) || i == 0) {
						opt.selected = true;
						j = opt.value;
					}
					list.options[i++] = opt;
				}
			}
		}
		
		list.length = i;
		if(listname == 'city'){
			changeDistric('distric' ,sectioncitys,j,0,0);
		}else{
			changeDistric('c_distric' ,sectioncitys,j,0,0);
		}
	}
	
	function changeDistric( listname , source, key, orig_key, orig_val){
		
		var list = eval( 'document.adminForm.' + listname );

		for (i in list.options.length) {
			list.options[i] = null;
		}
		var i = 0;
			opt = new Option();
			opt.value = 0;
			opt.text = '- Select District -';
			opt.selected = true;
			list.options[i++] = opt;
		for (x in source) {
			if (source[x][0] == key) {
				opt = new Option();
				opt.value = source[x][1];
				opt.text = source[x][2];
				
				if ((orig_key == key && orig_val == opt.value) || (i == 0) || ((key==1)&& (source[x][1] == 5))) {
					//opt.selected = true;
				}
				list.options[i++] = opt;
			
				
			}
		}
		
		
		list.length = i;
	}

	function showOtherHobbies(e,ex){
		var e_style = document.getElementById(e).style.display ;
		if(e_style==='none'){
			document.getElementById(e).style.display = '';
		}else{
			document.getElementById(e).style.display = 'none';
		}
	} 

	
</script>
<form  id="adminForm"  action="<?php echo JRoute::_("index.php?option=com_wrd&controller=profile")?>" method="post" name="adminForm" >
	<?php 
		echo JHtml::_('bootstrap.startTabSet', 'profile', array('active' => 'createid'));

		if($this->user->authorise('wrd.profile.createid', 'com_wrd')):
			echo JHtml::_('bootstrap.addTab', 'profile', 'createid', 'Create ID');
			echo $this->loadTemplate('account');
			echo JHtml::_('bootstrap.endTab');
		endif;
	 
		if($this->user->authorise('wrd.profile.basicinformation', 'com_wrd')):
			echo JHtml::_('bootstrap.addTab', 'profile', 'basicinformation', 'Basic Information');
			echo $this->loadTemplate('information');
			echo JHtml::_('bootstrap.endTab');
		endif;
		
		if($this->user->authorise('wrd.profile.businesscontact', 'com_wrd')):
			echo JHtml::_('bootstrap.addTab', 'profile', 'businesscontact', 'Business Contact');
			echo $this->loadTemplate('cinformation');
			echo JHtml::_('bootstrap.endTab');
		endif;
		
		if($this->user->authorise('wrd.profile.professionalism', 'com_wrd')):
			echo JHtml::_('bootstrap.addTab', 'profile', 'professionalism', 'Professionalism');
			echo $this->loadTemplate('professionalism');
			echo JHtml::_('bootstrap.endTab');
		endif;
		
		if($this->user->authorise('wrd.profile.personalinformation', 'com_wrd')):
			echo JHtml::_('bootstrap.addTab', 'profile', 'personalinformation', 'Personal Information');
			echo $this->loadTemplate('pinformation');
			echo JHtml::_('bootstrap.endTab');
		endif;
		
		if($this->user->authorise('wrd.profile.memberstatus', 'com_wrd')):
			echo JHtml::_('bootstrap.addTab', 'profile', 'memberstatus', 'Member Status');
			echo $this->loadTemplate('status');
			echo JHtml::_('bootstrap.endTab');
		endif;
		
		if($this->user->authorise('wrd.profile.spending', 'com_wrd')):
			echo JHtml::_('bootstrap.addTab', 'profile', 'spending', 'Spending');
			echo $this->loadTemplate('transaction');
			echo JHtml::_('bootstrap.endTab');
		endif;
		
		if($this->user->authorise('wrd.profile.pointhistory', 'com_wrd')):
			echo JHtml::_('bootstrap.addTab', 'profile', 'pointhistory', 'Point History');
			echo $this->loadTemplate('point');
			echo JHtml::_('bootstrap.endTab');
		endif;

		if($this->user->authorise('wrd.profile.redemption', 'com_wrd')):
			echo JHtml::_('bootstrap.addTab', 'profile', 'redemption', 'Redemption');
			echo $this->loadTemplate('redemption');
			echo JHtml::_('bootstrap.endTab');
		endif;
		
		if($this->user->authorise('wrd.profile.memberservices', 'com_wrd')):
			echo JHtml::_('bootstrap.addTab', 'profile', 'memberservices', 'Member Services');
			echo $this->loadTemplate('services');
			echo JHtml::_('bootstrap.endTab');
		endif;
		
		if($this->user->authorise('wrd.profile.complaint', 'com_wrd')):
			echo JHtml::_('bootstrap.addTab', 'profile', 'complaint', 'Complaints');
			echo $this->loadTemplate('complain');
			echo JHtml::_('bootstrap.endTab');
		endif;

		echo JHtml::_('bootstrap.endTabSet');
	?>
	<input type="hidden" name="created_id" value="<?php echo $this->user->id;?>" />
	<input type="hidden" name="user_id" value="<?php echo $this->data->user_id;?>" />
	<input type="hidden" name="controller" value="profile" />
	<input type="hidden" name="option" value="com_wrd" />
	<input type="hidden" name="id" value="<?php echo (int)$this->data->id; ?>" />
	<input type="hidden" name="task" value="" />
	<input type="hidden" name="tab" value="<?php echo JRequest::getVar('tab','create_account'); ?>" />

	<?php echo JHTML::_( 'form.token' ); ?>
</form>